import { Controller, Get, Post, Body, Patch, Param, Query, SetMetadata, UseGuards } from '@nestjs/common';
import { GuardRoleService } from './guard-role.service';
import { CreateGuardRoleDto } from './dto/create-guard-role.dto';
import { UpdateGuardRoleDto } from './dto/update-guard-role.dto';
import { GuardGuardRole } from '../guard/guard.guardRole'
/**
 * 测试路由守卫
 */
@Controller('guard-role')
export class GuardRoleController {
  constructor(private readonly guardRoleService: GuardRoleService) { }

  @Post()
  create(@Body() createGuardRoleDto: CreateGuardRoleDto) {
    return this.guardRoleService.create(createGuardRoleDto);
  }

  @Get()
  @UseGuards(GuardGuardRole) // 使用权限守卫
  findAll() {
    return this.guardRoleService.findAll();
  }

  @Get('/getList')
  @SetMetadata('roles', ['admin']) // 设置权限
  @UseGuards(GuardGuardRole) // 使用权限守卫
  getList(@Query() query: any) {

    return this.guardRoleService.findAll();
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.guardRoleService.findOne(+id);
  }


}
